#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Datetime: 2022/9/26 11:33
# @Author  : CHENWang
# @Site    : 
# @File    : weekly_get_cex_analysis_data.py
# @Software: PyCharm

"""
脚本说明:
"""

import os
from quant_researcher.quant.project_tool.localize import DATA_DIR
from quant_researcher.quant.project_tool.mail_tool import monitor_param, exceptionSimpleModel
from TQR_Applications.factor_database.crypto.trading_data_update import get_cex_analysis_data
from logger import logger
import os
import traceback
from task_monitor import task_to_db, send_error_to_email


if __name__ == '__main__':
    # 分析中心化交易所板块数据，
    # 需要用到中的数据os.path.join(DATA_DIR, r'all_history_ohlcvm_coinmarketcap\all_history_ohlcvm_coinmarketcap')，
    # 因此需要等全市场各个币的数据获取完毕，再执行该任务, 时间设定为周六下午6点
    logger.info("开始get_cex_analysis_data")
    task_to_db(os.path.basename(__file__), 'get_cex_analysis_data')
    try:
        get_cex_analysis_data()
    except Exception as e:
        msg = traceback.format_exc()
        logger.info(msg)
        send_error_to_email(script_name=os.path.basename(__file__), func_name="get_cex_analysis_data", message=msg)
        raise e
    task_to_db(os.path.basename(__file__), 'get_cex_analysis_data', 1)
    logger.info("成功get_cex_analysis_data")

    # 发送数据给宇婷
    exceptionSimple = exceptionSimpleModel()
    emailParam = monitor_param["email"]
    emailParam["subject"] = f"中心化交易所现货交易额与衍生品交易额占比, ETH现货交易额"
    file_path = os.path.join(DATA_DIR, r'cex_coins_data\statistics_data')
    file_name1 = os.path.join(file_path, f'all_cex_deri_volume.xlsx')
    file_name2 = os.path.join(file_path, f'all_cex_spot_volume.xlsx')
    file_path = os.path.join(DATA_DIR, r'trading_data')
    file_name3 = os.path.join(file_path, f'DIY ETH Trading Amount.csv')
    emailParam["file"] = [file_name1, file_name2, file_name3]
    # emailParam["sender"] = {"user": 'web3quant@163.com', "password": 'UBQWJTAECHMFVCNB', "host": 'smtp.163.com'}
    emailParam["sender"] = {"user": 'tianzhiguanlizixun@163.com', "password": 'VMUXBIXRSTMBJYDW', "host": 'smtp.163.com'}
    emailParam["receiver"] = ['jeffzhangzhenda@hotmail.com', '1207804643@qq.com', "zhanghang0427@163.com"]
    exceptionSimple.except_main(1, emailParam)